export default class LabelCommand {
    constructor() {
        this.Cammand = [];
    }

    clrCommand() {
        this.Command = [];
    }

    addStrToCommand(str) {
        if (!this.Command) {
            this.Command = [];
        }
        this.Command.push(str);
    }

    addGap(gap) {
        let str = "GAP " + gap + " mm," + 0 + " mm" + "\r\n";
        this.addStrToCommand(str);
    }

    addSize(width, height) {
        let str = "SIZE " + width + " mm," + height + " mm" + "\r\n";
        this.addStrToCommand(str);
    }

    addCashdrwer(m, t1, t2) {
        let str = "CASHDRAWER " + m + "," + t1 + "," + t2 + "\r\n";
        this.addStrToCommand(str);
    }

    addOffset(offset) {
        let str = "OFFSET " + offset + " mm" + "\r\n";
        this.addStrToCommand(str);
    }

    addSpeed(speed) {
        let str = "SPEED " + speed + "\r\n";
        this.addStrToCommand(str);
    }

    addDensity(density) {
        let str = "DENSITY " + density + "\r\n";
        this.addStrToCommand(str);
    }

    addDirection(direction, mirror) {
        let str = "DIRECTION " + direction + ',' + mirror + "\r\n";
        this.addStrToCommand(str);
    }

    addReference(x, y) {
        let str = "REFERENCE " + x + "," + y + "\r\n";
        this.addStrToCommand(str);
    }

    addShif(shift) {
        let str = "SHIFT " + shift + "\r\n";
        this.addStrToCommand(str);
    }

    addCls() {
        let str = "CLS\r\n";
        this.addStrToCommand(str);
    }

    addFeed(dot) {
        let str = "FEED " + dot + "\r\n";
        this.addStrToCommand(str);
    }

    addBackFeed(dot) {
        let str = "BACKFEED " + dot + "\r\n";
        this.addStrToCommand(str);
    }

    addFormFeed() {
        let str = "FORMFEED\r\n";
        this.addStrToCommand(str);
    }

    addHome() {
        let str = "HOME\r\n";
        this.addStrToCommand(str);
    }

    addPrintMore(m, n) {
        let str = "PRINT " + m + "," + n + "\r\n";
        this.addStrToCommand(str);
    }

    addPrint(m) {
        let str = "PRINT " + m + "\r\n";
        this.addStrToCommand(str);
    }

    addCodePage(page) {
        let str = "CODEPAGE " + page + "\r\n";
        this.addStrToCommand(str);
    }

    addSound(level, interval) {
        let str = "SOUND " + level + "," + interval + "\r\n";
        this.addStrToCommand(str);
    }

    addLimitFeed(n) {
        let str = "LIMITFEED " + n + "\r\n";
        this.addStrToCommand(str);
    }

    addSelfTest() {
        let str = "SELFTEST\r\n";
        this.addStrToCommand(str);
    }

    addBar(x, y, width, height) {
        let str = "BAR " + x + "," + y + "," + width + "," + height + "\r\n";
        this.addStrToCommand(str);
    }

    addText(x, y, font, rotation, Xscal, Yscal, text) {
        let str = "TEXT " + x + "," + y + "," + "\"" + font + "\"" + "," + rotation + "," + Xscal + "," + Yscal + "," + "\"" + text + "\"" + "\r\n";
        this.addStrToCommand(str);
    }

    add1DBarcode(x, y, type, height, readable, rotation, content) {
        let narrow = 2;
        let width = 2;
        let str = "BARCODE " + x + "," + y + "," + "\"" + type + "\"" + "," + height + "," + readable + "," + rotation + "," + narrow + "," + width + "," + "\"" + content + "\"" + "\r\n";
        this.addStrToCommand(str);
    }

    add1DBarcodeMore(x, y, type, height, readable, rotation, narrow, width, content) {
        let str = "BARCODE " + x + "," + y + "," + "\"" + type + "\"" + "," + height + "," + readable + "," + rotation + "," + narrow + "," + width + "," + "\"" + content + "\"" + "\r\n";
        this.addStrToCommand(str);
    }

    addBox(x, y, xend, yend, thickness) {
        let str = "BOX " + x + "," + y + "," + xend + "," + yend + "," + thickness + "\r\n";
        this.addStrToCommand(str);
    }

    // addBitmap(x,y, mode,nWidth, b) {
    //     if (b != null) {
    //         int width = (nWidth + 7) / 8 * 8;
    //         int height = b.getHeight() * width / b.getWidth();
    //         Bitmap grayBitmap = GpUtils.toGrayscale(b);
    //         Bitmap rszBitmap = GpUtils.resizeImage(grayBitmap, width, height);
    //         byte[] src = GpUtils.bitmapToBWPix(rszBitmap);
    //         height = src.length / width;
    //         width /= 8;
    //         let str = "BITMAP " + x + "," + y + "," + width + "," + height + "," + mode + ",";
    //         this.addStrToCommand(str);
    //         byte[] codecontent = GpUtils.pixToLabelCmd(src);
    //
    //         for(k = 0; k < codecontent.length; ++k) {
    //             this.Command.add(codecontent[k]);
    //         }
    //
    //         Log.d("LabelCommand", "codecontent" + codecontent);
    //     }
    //
    // }

    // addBitmapByMethod(x,y, LabelCommand.BITMAP_MODE mode,nWidth, Bitmap b) {
    //     if (b != null) {
    //         int width = (nWidth + 7) / 8 * 8;
    //         int height = b.getHeight() * width / b.getWidth();
    //         Log.d("BMP", "bmp.getWidth() " + b.getWidth());
    //         Bitmap rszBitmap = GpUtils.resizeImage(b, width, height);
    //         Bitmap grayBitmap = GpUtils.filter(rszBitmap, width, height);
    //         byte[] src = GpUtils.bitmapToBWPix(grayBitmap);
    //         height = src.length / width;
    //         width /= 8;
    //         let str = "BITMAP " + x + "," + y + "," + width + "," + height + "," + mode + ",";
    //         this.addStrToCommand(str);
    //         byte[] codecontent = GpUtils.pixToLabelCmd(src);
    //
    //         for(k = 0; k < codecontent.length; ++k) {
    //             this.Command.add(codecontent[k]);
    //         }
    //
    //         Log.d("LabelCommand", "codecontent" + codecontent);
    //     }
    //
    // }

    // addBitmap(x,y,nWidth, Bitmap bmp) {
    //     if (bmp != null) {
    //         int width = (nWidth + 7) / 8 * 8;
    //         int height = bmp.getHeight() * width / bmp.getWidth();
    //         Log.d("BMP", "bmp.getWidth() " + bmp.getWidth());
    //         Bitmap rszBitmap = GpUtils.resizeImage(bmp, width, height);
    //         byte[] bytes = GpUtils.printTscDraw(x, y, LabelCommand.BITMAP_MODE.OVERWRITE, rszBitmap);
    //
    //         for(i = 0; i < bytes.length; ++i) {
    //             this.Command.add(bytes[i]);
    //         }
    //
    //         this.addStrToCommand("\r\n");
    //     }
    //
    // }

    addErase(x, y, xwidth, yheight) {
        let str = "ERASE " + x + "," + y + "," + xwidth + "," + yheight + "\r\n";
        this.addStrToCommand(str);
    }

    addReverse(x, y, xwidth, yheight) {
        let str = "REVERSE " + x + "," + y + "," + xwidth + "," + yheight + "\r\n";
        this.addStrToCommand(str);
    }

    addQRCode(x, y, level, cellwidth, rotation, data) {
        let str = "QRCODE " + x + "," + y + "," + level + "," + cellwidth + "," + 'A' + "," + rotation + "," + "\"" + data + "\"" + "\r\n";
        this.addStrToCommand(str);
    }

    getCommand() {
        if (!this.Command) {
            this.Command = [];
        }
        return this.Command;
    }

    addQueryPrinterType() {
        let str = "~!T\r\n";
        this.addStrToCommand(str);
    }

    //TODO::未处理
    addQueryPrinterStatus() {
        this.addStrToCommand([27, 33, 63]);
        // this.Command.add((byte)27);
        // this.Command.add((byte)33);
        // this.Command.add((byte)63);
    }

    //TODO::未处理
    addResetPrinter() {
        this.addStrToCommand([27, 33, 82]);
        // this.Command.add((byte)27);
        // this.Command.add((byte)33);
        // this.Command.add((byte)82);
    }

    addQueryPrinterLife() {
        let str = "~!@\r\n";
        this.addStrToCommand(str);
    }

    addQueryPrinterMemory() {
        let str = "~!A\r\n";
        this.addStrToCommand(str);
    }

    addQueryPrinterFile() {
        let str = "~!F\r\n";
        this.addStrToCommand(str);
    }

    addQueryPrinterCodePage() {
        let str = "~!I\r\n";
        this.addStrToCommand(str);
    }

    addPeel(enable) {
        if (enable == 0) {
            let str = "SET PEEL " + enable + "\r\n";
            this.addStrToCommand(str);
        }
    }

    addTear(enable) {
        let str = "SET TEAR " + enable + "\r\n";
        this.addStrToCommand(str);
    }

    addCutter(enable) {
        let str = "SET CUTTER " + enable + "\r\n";
        this.addStrToCommand(str);
    }

    addCutterBatch() {
        let str = "SET CUTTER BATCH\r\n";
        this.addStrToCommand(str);
    }

    addCutterPieces(number) {
        let str = "SET CUTTER " + number + "\r\n";
        this.addStrToCommand(str);
    }

    addReprint(enable) {
        let str = "SET REPRINT " + enable + "\r\n";
        this.addStrToCommand(str);
    }

    addPrintKey(enable) {
        let str = "SET PRINTKEY " + enable + "\r\n";
        this.addStrToCommand(str);
    }

    addPrintKey(m) {
        let str = "SET PRINTKEY " + m + "\r\n";
        this.addStrToCommand(str);
    }

    addPartialCutter(enable) {
        let str = "SET PARTIAL_CUTTER " + enable + "\r\n";
        this.addStrToCommand(str);
    }

    addQueryPrinterStatus(mode) {
        let str = "SET RESPONSE " + mode + "\r\n";
        this.addStrToCommand(str);
    }

    addUserCommand(command) {
        this.addStrToCommand(command);
    }
}

LabelCommand.BARCODETYPE = {
    CODE128: "128",
    CODE128M: "128M",
    EAN128: "EAN128",
    ITF25: "25",
    ITF25C: "25C",
    CODE39: "39",
    CODE39C: "39C",
    CODE39S: "39S",
    CODE93: "93",
    EAN13: "EAN13",
    EAN13_2: "EAN13+2",
    EAN13_5: "EAN13+5",
    EAN8: "EAN8",
    EAN8_2: "EAN8+2",
    EAN8_5: "EAN8+5",
    CODABAR: "CODA",
    POST: "POST",
    UPCA: "UPCA",
    UPCA_2: "UPCA+2",
    UPCA_5: "UPCA+5",
    UPCE: "UPCE13",
    UPCE_2: "UPCE13+2",
    UPCE_5: "UPCE13+5",
    CPOST: "CPOST",
    MSI: "MSI",
    MSIC: "MSIC",
    PLESSEY: "PLESSEY",
    ITF14: "ITF14",
    EAN14: "EAN14"
};

LabelCommand.BITMAP_MODE = {
    OVERWRITE: 0,
    OR: 1,
    XOR: 2
};

LabelCommand.CODEPAGE = {
    PC437: 437,
    PC850: 850,
    PC852: 852,
    PC860: 860,
    PC863: 863,
    PC865: 865,
    WPC1250: 1250,
    WPC1252: 1252,
    WPC1253: 1253,
    WPC1254: 1254
};

LabelCommand.DENSITY = {
    DNESITY0: 0,
    DNESITY1: 1,
    DNESITY2: 2,
    DNESITY3: 3,
    DNESITY4: 4,
    DNESITY5: 5,
    DNESITY6: 6,
    DNESITY7: 7,
    DNESITY8: 8,
    DNESITY9: 9,
    DNESITY10: 10,
    DNESITY11: 11,
    DNESITY12: 12,
    DNESITY13: 13,
    DNESITY14: 14,
    DNESITY15: 15
};

LabelCommand.DIRECTION = {
    FORWARD: 0,
    BACKWARD: 1
};

LabelCommand.EEC = {
    LEVEL_L: "L",
    LEVEL_M: "M",
    LEVEL_Q: "Q",
    LEVEL_H: "H"
};

LabelCommand.FONTMUL = {
    MUL_1: 1,
    MUL_2: 2,
    MUL_3: 3,
    MUL_4: 4,
    MUL_5: 5,
    MUL_6: 6,
    MUL_7: 7,
    MUL_8: 8,
    MUL_9: 9,
    MUL_10: 10
};

LabelCommand.FONTTYPE = {
    FONT_1: "1",
    FONT_2: "2",
    FONT_3: "3",
    FONT_4: "4",
    FONT_5: "5",
    FONT_6: "6",
    FONT_7: "7",
    FONT_8: "8",
    FONT_9: "9",
    FONT_10: "10",
    SIMPLIFIED_CHINESE: "TSS24.BF2",
    TRADITIONAL_CHINESE: "TST24.BF2",
    KOREAN: "K"
};

LabelCommand.FOOT = {
    F2: 0,
    F5: 1
};

LabelCommand.MIRROR = {
    NORMAL: 0,
    MIRROR: 1
};

LabelCommand.READABEL = {
    DISABLE: 0,
    EANBEL: 1
};

LabelCommand.RESPONSE_MODE = {
    ON: "ON",
    OFF: "OFF",
    BATCH: "BATCH"
};

LabelCommand.ROTATION = {
    ROTATION_0: 0,
    ROTATION_90: 90,
    ROTATION_180: 180,
    ROTATION_270: 270
};

LabelCommand.SPEED = {
    SPEED1DIV5: 1.5,
    SPEED2: 2.0,
    SPEED3: 3.0,
    SPEED4: 4.0
};

LabelCommand.ENABLE = {
    OFF: 0,
    ON: 1
}
